<!DOCTYPE html>
<html style="background: #eee">
<head lang="en">
    <meta charset="UTF-8">
    <meta name='apple-touch-fullscreen' content='yes'>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta content="fullscreen=yes,preventMove=no" name="ML-Config">
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="format-detection" content="telephone=no,email=no,address=no"/>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>硒豆转金花</title>
    <link rel="stylesheet" href="/style/lh/css/style.css">
    <link type="text/css" rel="stylesheet" href="/style/css/sweet-alert.css">
    <script src="/style/wei/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/style/lh/js/style.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/style/js/sweet-alert.min.js"></script>
<script type="text/javascript">     
(function () {
    var b = document.documentElement,
        a = function () {
            var a = b.getBoundingClientRect().width;
            b.style.fontSize = (a / 1080) * 100+ "px";
        }, c = null;
    window.addEventListener("resize", function () {
        clearTimeout(c);
        c = setTimeout(a, 300);
    });
    a();
})();
</script>
<style>
.b-input>input{display: none;}
.b-input>label{ position: relative; margin-right:1.2rem;font-size: 0.4rem; color: #333;}
.b-input>label::before{ display: inline-block; content: ""; width: 16px; height: 16px; border-radius: 50%; background-color: #f2f2f2; margin-right: 0.12rem; vertical-align: middle;}
.b-input>input:checked+label::before{ border: 1px solid rgb(219, 219, 219);}
.b-input>input:checked+label::after{ display: inline-block; content: ""; width: 8px; height: 8px; border-radius: 50%; position: absolute; left: 5px; bottom: 5px; background-color:#e14504;}
dd span{font-size: .4rem;}
</style>
</head>
<body>
<form id="form_tx">
    <div class="b-bg">
        <h3 id="user_text">硒豆余额</h3>
        <h2 id="user_money"><?=($this->balance['money']*1)?></h2>
    </div>
    <div class="b-navbar">
        <dl>             
            <dd>
                <i>转换数量：</i>
                <input type="text" name="number" id="number" placeholder="0">
            </dd>
            <dd>
                <i>可得金花：</i>
                <span id="kede">--</span>
            </dd>
            <dd>
                <span>说明：转换数量<?=$this->setting['min_transfer_money'];?>起，转换手续费<?=$this->setting['transfer_percent']*100;?>%（最少<?=$this->setting['min_transfer_charge'];?>）</span>
            </dd>

        </dl>
    </div>
    <input type="hidden" name="act" value="sub_transfer">
    <div class="b-btn" onClick="sub()">确认转换</div>
 </form>
</body>
<script>
    
var gold_money = <?=$this->balance['money']  ? :0;?>,
_min = <?=$this->setting['min_transfer_money'] ? : 0;?>,
_percent = <?=$this->setting['transfer_percent'] ? : 0;?>,
_less = <?=$this->setting['min_transfer_charge'] ? : 0 ;?>;

$(document).ready(function(e){

    $("#number").on("keyup",function(){

        _count($(this).prop("value"));

    });

});

function _count(v)
{
    var f = false;

    if(v!="")
    {
        var num = parseInt(v),shoux = 0;
        if(v>0 && v>=_min)
        {
            if(_percent>0)
            {
                shoux = v * _percent;
            }

            if(_less>0 && shoux < _less)
            {
                shoux = _less;
            }

            v = v - shoux;
            f = true;

            $("#kede").html(v);
        }
    }
    

    if(!f)
    {
        $("#kede").html('--');
    }
}

function sub() {
     

     

     if($("#number").prop("value") =="" || $("#number").prop("value") <1){
    	 swal("填写转换数量");
         return false;

     }
     if(isNaN($("#number").prop("value"))){
    	 swal("转账数量必须是数字");
         return false;
     }
     if(parseInt($("#number").prop("value")) >gold_money){
    	 swal("转账数量不能大于余额");
         return false;

     }

     $.ajax({
         type: 'post',
         url: '/wallet/ajax',
         data: $("#form_tx").serialize() + "&mr=" + Math.random(),
         dataType: 'json',
         success: function(data) {
                 if (data.code == 200) {
                     swal("转换成功", false, "success");
                     setTimeout(function(){
                       window.location.href = '/wallet';
                     },2000);
                 } else {
                	    swal(data.msg+"["+data.code+"]",false,"error");
                 }

         }
     });

}

</script>
</html>